package com.self.serviceedu.controller;


import com.self.commonutils.R;
import com.self.serviceedu.entity.EduSubject;
import com.self.serviceedu.entity.subject.OneSubject;
import com.self.serviceedu.service.EduSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author xiaozeng
 * @since 2020-09-12
 */
@Api(description = "课程分类管理")
@CrossOrigin
@RestController
@RequestMapping("/eduservice/subject")
public class EduSubjectController {

    @Autowired
    private EduSubjectService subjectService;

    //添加课程分类
    //获取上传的文件，读取对应的数据保存进数据库
    @ApiOperation(value = "添加课程分类")
    @PostMapping("addSubject")
    public R addSubject(MultipartFile file){

        //上传进来的文件
        subjectService.saveSubject(file,subjectService);
        return R.ok();
    }

    //课程分类的列表功能（树形结构）
    @ApiOperation(value = "课程分类列表功能")
    @GetMapping("getAllSubject")
    public R getAllSubject(){

        List<OneSubject> list =  subjectService.getAllOneTwoSubject();
        return R.ok().data("list",list);
    }
}

